package logic

import (
	"context"
	"houses_srv/housesclient"
	"houses_srv/models"

	"houses_srv/houses"
	"houses_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHouseLogic {
	return &ListHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListHouseLogic) ListHouse(in *houses.ListHouseRequest) (*houses.ListHouseResponse, error) {
	// todo: add your logic here and delete this line

	var h models.House
	house, err := h.ListHouse()
	if err != nil {
		return nil, err
	}
	var houseList []*housesclient.ListHouse
	for _, houses := range house {
		list := housesclient.ListHouse{
			HouseId:   int64(houses.ID),
			Title:     houses.Title,
			Image:     houses.Image,
			Price:     int64(houses.Price),
			Fool:      float32(houses.Fool),
			HouseType: houses.HouseType,
		}
		houseList = append(houseList, &list)
	}

	return &houses.ListHouseResponse{List: houseList}, nil
}
